<?php 
namespace app\api\controller;

use app\api\ApiController;
use common\service\AuthService;
use common\service\ChainService;
use think\Request;

class Issue extends ApiController
{
    public $steamInfo = [];//用户steam信息

    public function __construct()
    {
        parent::__construct();
        $this->steamInfo = AuthService::getInstance()->verifyToken();
        $this->steamInfo = empty($this->steamInfo) ? [] : $this->steamInfo;
    }

    public function notify()
    {
        $ret = ChainService::getInstance()->notify();
        if($ret == true){
            return $this->successJson();
        }elseif($ret == -1){
            return $this->errorMessage(SIGN_FAIL_NO, SIGN_FAIL_ERROR);
        }else{
            return $this->errorMessage(REQUEST_NO, REQUEST_ERROR);
        }
    }

    /**
     * 销毁接口
     * @param null $botInvIds
     * @return \think\response\Json
     */
    public function destroyAsset($botInvIds = null)
    {
        if(empty($this->steamInfo)){
            return $this->errorMessage(BAD_ACCESS_TOKEN_NO, BAD_ACCESS_TOKEN_ERROR);
        }
        $result = $this->validate(
            [
                'botInvIds' => $botInvIds
            ],
            [
                'botInvIds' => 'require'
            ]
        );
        $userId = $this->steamInfo['user_id'];

        if(true !== $result){
            return $this->errorParams($result);
        }

        $res = ChainService::getInstance()->takeBack($userId, $botInvIds);
        if($res){
            return $this->successJson();
        }else{
            return $this->errorMessage(REQUEST_NO, REQUEST_ERROR);
        }
    }

}